################################################################################
#
#  COIN_Cbc_examples: Automated script to build examples for COIN-Cbc
#
################################################################################
SET(COIN_CBC_EXAMPLE_DIR
    ${CBC_ROOT_DIR}/Cbc/examples)
    
SET(COIN_CBC_EXAMPLE_SRCS_NR
    ${COIN_CBC_EXAMPLE_DIR}/CbcCompareUser.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcSolver2.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcSolver3.cpp
    ${COIN_CBC_EXAMPLE_DIR}/ClpQuadInterface.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcBranchFollow2.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcBranchUser.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcBranchLink.cpp
    ${COIN_CBC_EXAMPLE_DIR}/CbcSolverLongThin.cpp
    ${COIN_CBC_EXAMPLE_DIR}/ClpQuadInterface.cpp
)

#-------------------------------------------------------------------------------
#Glob all files in the folder
#-------------------------------------------------------------------------------
FILE(GLOB CBC_EXAMPLE_SRCS
    ${COIN_CBC_EXAMPLE_DIR}/*.cpp
)

#-------------------------------------------------------------------------------
#Exclude COIN_CBC_EXAMPLE_SRCS_NR files from COIN_CBC_EXAMPLE_SRCS
#-------------------------------------------------------------------------------
FOREACH(B_SRC ${COIN_CBC_EXAMPLE_SRCS_NR})
  #Remove CbcGeneric files
  LIST(REMOVE_ITEM CBC_EXAMPLE_SRCS "${B_SRC}")
ENDFOREACH(B_SRC ${COIN_CBC_EXAMPLE_SRCS_NR})

#-------------------------------------------------------------------------------
#Bugs: These examples have problems linking
#-------------------------------------------------------------------------------
LIST(REMOVE_ITEM CBC_EXAMPLE_SRCS 
     "${COIN_CBC_EXAMPLE_DIR}/driver3.cpp"
     "${COIN_CBC_EXAMPLE_DIR}/driver4.cpp"
)

#-------------------------------------------------------------------------------
#Build all executables
#-------------------------------------------------------------------------------
SET(CBC_EXAMPLE_EXE "")

FOREACH(B_SRC ${CBC_EXAMPLE_SRCS})
  #Get the file name and build its corresponding executable
  GET_FILENAME_COMPONENT(T_FILE ${B_SRC} NAME)
  STRING(REGEX REPLACE ".cpp" "" T_FILE1 ${T_FILE})
  SET(${CBC_EXAMPLE_EXE} ${T_FILE1})
  ADD_EXECUTABLE(${T_FILE1} ${B_SRC} ${COIN_CBC_EXAMPLE_SRCS_NR})
  TARGET_LINK_LIBRARIES(${T_FILE1} 
                        COIN_CbcSolver 
                        COIN_Cbc 
                        COIN_Cgl 
                        COIN_OsiClp 
                        COIN_Osi 
                        COIN_Clp 
                        COIN_CoinUtils
                        COIN_OsiCbc)
  INSTALL(
    TARGETS
      ${T_FILE1}
    DESTINATION
      bin/example
  )
ENDFOREACH(B_SRC ${COIN_CBC_EXAMPLE_SRCS_NR})